/**
 * @Description: 单个button
 * @Author: skj
 */
import React, {Component} from "react";
import {View, StyleSheet, ViewPropTypes, Text} from "react-native";
import {Button} from 'react-native-elements';
import PropTypes from "prop-types";

export default class BTButton extends Component {
	constructor(props) {
		super(props);
		this.state = {
			isCanClickDoubleBtn: true
		}
	}

	//属性传参
	static propTypes = {
		container: ViewPropTypes.style,
		title: PropTypes.string.isRequired,
		titleStyle: Text.propTypes.style,
		buttonStyle: ViewPropTypes.style,
		disableButtonStyle: ViewPropTypes.style,
		disabledTitleStyle: Text.propTypes.style,
		containerViewStyle: ViewPropTypes.style,//按钮的内部containerstyle
		disabled: PropTypes.bool,
		onPress: PropTypes.func.isRequired,
	};
	//默认属性
	static defaultProps = {
		disabled: false,
	};

	componentDidMount() {
	}

	render() {
		const {title, titleStyle, buttonStyle, disableButtonStyle, containerViewStyle, disabled, onPress, disabledTitleStyle} = this.props;
		return (
			<Button
				title={title}
				onPress={() => {
					if (this.state.isCanClickDoubleBtn) {
						this.state.isCanClickDoubleBtn = false;
						onPress && onPress()
						setTimeout(() => {
							this.state.isCanClickDoubleBtn = true;
						}, 800);
					}
				}}
				buttonStyle={[styles.buttonStyle, buttonStyle]}
				containerStyle={[containerViewStyle]}
				titleStyle={[styles.titleStyle, titleStyle]}
				disabledStyle={[styles.disableButtonStyle, disableButtonStyle]}
				disabledTitleStyle={[styles.disabledTitleStyle, disabledTitleStyle]}
				disabled={disabled}
			/>
		);
	}
}
const styles = StyleSheet.create({
	titleStyle: {
		fontSize: 15,
		color: '#fff'
	},
	buttonStyle: {
		backgroundColor: '#E83C36',
		// marginHorizontal: 15,
		height: 40,
		borderColor: 'transparent',
		borderRadius: 5,
		borderWidth: 0
	},
	disableButtonStyle: {
		backgroundColor: '#c5c4c4',
		borderWidth: 0
	},
	disabledTitleStyle: {
		color: '#FFFFFF'
	}
});